home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / dev / c / MemPools.lha / malloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-12  |  2.4 KB  |  105 lines

  1. /**
  2. ***  MemPools:  malloc() replacement using standard Amiga pool functions.
  3. ***  Copyright  (C)  1994    Jochen Wiedmann
  4. ***    changes       1998    Matthias Andree
  5. ***
  6. ***  This program is free software; you can redistribute it and/or modify
  7. ***  it under the terms of the GNU General Public License as published by
  8. ***  the Free Software Foundation; either version 2 of the License, or
  9. ***  (at your option) any later version.
  10. ***
  11. ***  This program is distributed in the hope that it will be useful,
  12. ***  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ***  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ***  GNU General Public License for more details.
  15. ***
  16. ***  You should have received a copy of the GNU General Public License
  17. ***  along with this program; if not, write to the Free Software
  18. ***  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. ***
  20. ***
  21. ***  This file contains the malloc() replacement.
  22. ***
  23. ***
  24. ***  Computer:  Amiga 4000
  25. ***
  26. ***  Compilers: gcc 2.7.2
  27. ***             SAS/C 6.58
  28. ***
  29. ***
  30. ***  Author:    Jochen Wiedmann
  31. ***             Am Eisteich 9
  32. ***       72555 Metzingen
  33. ***             Germany
  34. ***
  35. ***             Phone: (0049) 7123 14881
  36. ***             Internet: jochen.wiedmann@uni-tuebingen.de
  37. ***
  38. ***  Bugfixes
  39. ***  Updates:   Matthias Andree
  40. ***             Stormstr. 14
  41. ***             58099 Hagen
  42. ***             Germany
  43. ***
  44. ***             Phone: +49-(0)23 31-96 30 72
  45. ***
  46. ***             E-Mail: mandree@dosis.uni-dortmund.de
  47. ***
  48. **/
  49.  
  50.  
  51.  
  52.  
  53. /*
  54.     Include files and compiler specific stuff
  55. */
  56. #include <stdlib.h>
  57. #include <string.h>
  58. #include <errno.h>
  59. #include <exec/types.h>
  60. #if defined(__SASC)
  61. #include "my_alib_protos.h"
  62. #else
  63. #include <clib/alib_protos.h>
  64. #endif
  65. #include <proto/exec.h>
  66.  
  67. #include "mempools.h"
  68.  
  69.  
  70.  
  71. #ifdef DEBUG
  72. #define ADDSIZE (sizeof(memBlock)+sizeof(memBlockEnd))
  73. #else
  74. #define ADDSIZE (sizeof(memBlock))
  75. #endif
  76.  
  77.  
  78.  
  79. void *malloc(size_t size)
  80.  
  81. {
  82.     if (size) {
  83.     memBlock *ptr;
  84.  
  85.     if ((ptr = LibAllocPooled(__MemPool, (ULONG)size + ADDSIZE))) {
  86.         ptr->size = size;
  87. #ifdef DEBUG
  88.         AddTail((struct List *) &memList, (struct Node *) ptr);
  89.         ptr->realSize = size + ADDSIZE;
  90.         memcpy(ptr->lowerBoundary, meatBeaf, sizeof(meatBeaf));
  91.         {
  92.         memBlockEnd *eptr;
  93.  
  94.         eptr = (memBlockEnd *) (((char *)(ptr+1))+size);
  95.         memcpy(eptr->upperBoundary, meatBeaf, sizeof(meatBeaf));
  96.         }
  97. #endif
  98.         return(ptr+1);
  99.     }
  100.  
  101.     errno = ENOMEM;
  102.     }
  103.     return(NULL);
  104. }
  105.